﻿
module AsyncTest
open System.Net
open Microsoft.FSharp.Control.WebExtensions

let OneFuncAsync t =
    async {
        printfn "Sleep %ds Start!" t
        let result = Async.Sleep (t * 1000)
        printfn "Sleep %ds middle!" t
        let! result1 = result
        printfn "Sleep %ds End!" t
        result1
    }

let OneFuncAsyncForCSharp t =
    Async.StartAsTask (OneFuncAsync t)
    
let fetchAsync(name, url:string) =
    async {
        try
            let uri = new System.Uri("url")
            let webClient = new WebClient()
            let! html = webClient.AsyncDownloadString(uri)
            printfn "Read %d characters for %s" html.Length name
        with
            | ex -> printfn "%s" (ex.Message);
    }

let OneFuncAsyncTest =
    let compution1 = OneFuncAsync 10
    let compution2 = OneFuncAsync 5
    let se = seq{ compution1; compution2}
    printfn "OneFuncAsyncTest"
    Async.Parallel se
    |> Async.RunSynchronously


